﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using LiveCharts;
using LiveCharts.Wpf;

namespace Dt261.Views
{
    public class TestClass
    {
        public string Name { get; set; }

        public int ID { get; set; }

        public int Age { get; set; }
    }
    /// <summary>
    /// WindowTest.xaml 的交互逻辑
    /// </summary>
    public partial class WindowTest : Window
    {
        List<TestClass> Test;
        string NAME = "N";
        public WindowTest()
        {
            InitializeComponent();

            Test = new List<TestClass>();

            for (var i = 0; i < 5; i++)
            {
                Test.Add(new TestClass() { Age = i, ID = 1, Name = NAME + i.ToString() });
            }
            DG.ItemsSource = Test;

            //DG.AutoSizeRowsMode  = DataGridViewAutoSizeColumnsMode.AllCells;

            //
            SeriesCollection = new SeriesCollection
            {
                new ColumnSeries
                {
                    Title = "",
                    // 2015的条形值
                    // 动态改变数据只需要更改此处的 Values 便可
                    //Values = new ChartValues<double> { 10, 30, 20, 15 }//需要加上10去显示，因有-10
                     Values = new ChartValues<double> {  0, 10, 30, 25 }
                }
            };

            //adding series will update and animate the chart automatically
            //SeriesCollection.Add(new ColumnSeries
            //{
            //    Title = "2016",
            //    // 2016的条形值
            //    // 动态改变数据只需要更改此处的 Values 便可
            //    Values = new ChartValues<double> { 11, 56, 42 }
            //});
            //SeriesCollection[1].Values.Add(48d);
            //SeriesCollection.Add(new ColumnSeries
            //{
            //    Title = "2016",
            //    // 2016的条形值
            //    // 动态改变数据只需要更改此处的 Values 便可
            //    Values = new ChartValues<double> { 11, 56, 42 }
            //});

            //also adding values updates and animates the chart automatically


            Labels = new[] { "1", "2", "3", "4" };
          
            Formatter = value=> (value-10).ToString("G");



            SeriesCollection2 = new SeriesCollection
    {
        // 匿名新建LineSeries对象
        new LineSeries
        {
            // 折线的名称
            Title = "左耳DE",
            Fill = Brushes.Transparent,
            // 折线的拐点值
            PointGeometry = DefaultGeometries.None,
            Values = new ChartValues<double> { 4, 6, 5, 2, 2.5, 6, 5, 2, 2.5}
        },
        //new LineSeries
        //{
        //    Title = "Series 2",
        //    Values = new ChartValues<double> { 6, 7, 3, 4 ,6 },
        //    // 折线拐点的表示形状，默认为原点
        //    PointGeometry = null
        //},
        //new LineSeries
        //{
        //    Title = "Series 3",
        //    Values = new ChartValues<double> { 4,2,7,2,7 },
        //    // 折线拐点的表示形状，默认为原点，这里是正方形
        //    PointGeometry = DefaultGeometries.Square,
        //    // 折线拐点的形状尺寸
        //    PointGeometrySize = 15
        //}
    };

            // X轴的坐标值
            YLabels = new[] {  "2", "4", "6", "8", "10", "12", "14", "16", "18" };
            // Y轴坐标值
            YFormatter = value => value.ToString("G");

            ////modifying the series collection will animate and update the chart
            //// 动态添加折线"Series 4"
            //SeriesCollection2.Add(new LineSeries
            //{
            //    Title = "Series 4",
            //    Values = new ChartValues<double> { 5, 3, 2, 4 },
            //    LineSmoothness = 0, //0: straight lines, 1: really smooth lines
            //    PointGeometry = Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"),
            //    PointGeometrySize = 50,
            //    // 折线拐点的表示形状，默认为原点，这里是正方形
            //    PointForeground = Brushes.Gray
            //});

            ////modifying any series values will also animate and update the chart
            //// 动态为折线"Series 4"添加一个值
            //SeriesCollection2[3].Values.Add(5d);


            DataContext = this;
        }

        // 图形数据属性
        public SeriesCollection SeriesCollection { get; set; }
        public SeriesCollection SeriesCollection2 { get; set; }

        // 标签属性
        public string[] Labels { get; set; }
        // Y轴坐标属性
        public Func<double, string> Formatter { get; set; }

        public string[] YLabels { get; set; }
        public Func<double, string> YFormatter { get; set; }
        

    }
}
